import { Component } from '@angular/core';
import { AgRendererComponent } from '@ag-grid-community/angular';
import { ICellRendererParams } from '@ag-grid-community/core';
import { AreaService } from '@core/services/masterdata/area.service';
import { map, mergeMap } from 'rxjs/operators';

@Component({
  selector: 'apes-render-city-picker',
  template: `
    {{this.getName(params.value)}}
  `,
  styles: [],
})
export class ApesRenderCityPicker implements AgRendererComponent {
  value: any;
  params: ICellRendererParams;

  // province_key = [];
  // provinces = {};

  constructor(
    // private areaService:AreaService,
  ) {
  }

  refresh(params: any): boolean {
    return false;
  }

  agInit(params: ICellRendererParams): void {
    this.params = params;
  }

  getName(params) {
    if (params) {
      let data = this.params.data;
      if(data.hasOwnProperty('renderAddr')){
        this.value = data['renderAddr'];
      }else{
        this.value = '';
        if(data.hasOwnProperty('province')) {
          this.value += data['province'].name;
        }
        if(data.hasOwnProperty('city')) {
          this.value += ' / ' + data['city'].name;
        }
        if(data.hasOwnProperty('district')) {
          this.value += ' / ' + data['district'].name;
        }
        // this.value += this.params.value.name;
      }

      return this.value;
    }
  }

}
